home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-08-17 | 3.6 KB | 127 lines | [TEXT/MPS ] |
- ;
- ; Encoding pictures external routine for 4D
- ; written by François Marchal, © ACI 1992
- ;
- ; Parameters :
- ; -> Picture to encode
- ; -> Longint key word (you need the same key to encode and to decipher the picture)
- ;
-
- CASE OBJ
- INCLUDE 'traps.a'
-
- picsize EQU 104
- cle EQU 100
- signature EQU 98
- masignature EQU $464D
- picend EQU 6
-
- EXPORT EncryptPicture
-
- EncryptPicture PROC
- CODE
-
- LINK A6,#$0
- MOVEM.L D4-D7/A4,-(A7) ; save the used registers
- MOVEA.L 12(A6),A4
- MOVE.L (A4),A4 ; A4 : Handle on the picture to encode
- BEQ Fini ; if the Handle passed is Nil, don't do anything
-
- MOVE.L (A4),A0
- MOVE.W signature(A0),D0
- CMPI.W #masignature,D0 ; verify if the handle hasn't been signed
- BEQ fini ; if the picture has already been encoded, don't do anything
-
-
- MOVE.L A4,A0
- _GetHandleSize
- MOVE.L D0,D7 ; store the size of the Handle in D7
- BEQ.S Fini ; If the Handle is empty, stop
-
- MOVE.L A4,A0 ; to insert the lock here
- ADD.L #picsize,D0 ; make the Handle as big as the size of the new picture
- _SetHandleSize
- MOVE.W D0,D0
- BMI.S Fini
-
- SUBQ.L #picend,D7
- MOVE.L (A4),A0
- ADDA.L D7,A0 ; move the 6 bytes from the picend
- MOVEA.L A0,A1 ; to the end of the block
- ADDA.L #picsize,A1
- MOVE.L (A0)+,(A1)+
- MOVE.W (A0)+,(A1)
- ; take the old header of the picture and place it at the end of the block
- MOVE.L (A4),A0 ; Source -> move the pointer to the beginning of the data
- MOVE.L A0,A1 ; Dest -> calculate a pointer to the end of the data
- ADDA.L D7,A1 ;
- MOVE.L #picsize,D0 ; Lenght -> the size of the header
- _BlockMove ; move the header to the end of the block
-
- LEA Verrou,A0 ; Source -> take the address of the data of the lock
- MOVE.L (A4),A1 ; Dest -> take the Handle dereferened
- MOVE.L #picsize,D0 ; Lenght -> number of bytes to move
- _BlockMove ; place our own header at the beginning of the picture
-
-
- MOVE.L 8(A6),A0 ; dereferencing (parameter passed in var)
- MOVE.L (A0),D4 ; of the encoding key
- MOVE.L (A4),A0 ; saving of the key after the signature
- MOVE.L D4,Cle(A0) ;
-
- MOVE.L (A4),A0
- ADDA.L #Picsize,A0 ; A0 : pointer to the data to encode
-
- MOVE.L D7,D6
- ANDI.L #$1F,D6 ; D6 -> the remainder of the whole division of D7 by 32
-
- LSR.L #5,D7 ; divide by 32 of the size of the Handle
- BEQ.S GereReste ; allows us to know the number of passes in the loop
-
- SUBQ #1,D7 ; take 1 to D7 for the dbra
-
- Loop:
- MOVE.L D4,D5
- SUB.L D7,D5
- EOR.L D5,(A0)+ ; 1
- EOR.L D5,(A0)+ ; 2
- EOR.L D5,(A0)+ ; 3
- EOR.L D5,(A0)+ ; 4
- EOR.L D5,(A0)+ ; 5
- EOR.L D5,(A0)+ ; 6
- EOR.L D5,(A0)+ ; 7
- EOR.L D5,(A0)+ ; 8 x 4 = 32 bytes processed by the loop
-
- DBRA D7,Loop
-
- GereReste: ; take care of the remaining bytes
- CMPI.L #0,D6
- BLE.s Fini
- EOR.B D6,(A0)+
- SUBQ #1,D6
- BRA.S GereReste
-
- Fini:
- MOVEM.L (A7)+,D4-D7/A4 ; restoring the registers
- UNLK A6
- MOVEA.L (A7)+,A0 ; read the return address
- ADDQ.L #$8,A7 ; take the parameters off of the stack
- JMP (A0) ; and return to the calling point
-
- Verrou:
- DC.B $00,$61,$00,$00,$00,$00,$00,$10,$00,$10 ; lock picture
- DC.B $11,$01,$A0,$00,$82,$A0,$00,$8E,$01,$00
- DC.B $0A,$00,$00,$00,$00,$00,$10,$00,$10,$90
- DC.B $00,$02,$00,$52,$00,$7E,$00,$62,$00,$8E
- DC.B $00,$52,$00,$7E,$00,$62,$00,$8E,$00,$00
- DC.B $00,$00,$00,$10,$00,$10,$00,$00,$00,$00
- DC.B $07,$C0,$0F,$E0,$1C,$70,$18,$30,$18,$30
- DC.B $18,$30,$3F,$F8,$3F,$F8,$3C,$78,$3C,$78
- DC.B $3E,$F8,$3E,$F8,$3F,$F8,$3F,$F8,$00,$00
- DC.B $A0,$00,$8F,$A0,$00,$83,$FF,$00
-
- DC.W masignature
- DC.L $0
-
- ENDP
- END